Field of the Disclosure
This disclosure relates generally to managing accesses to shared resources in a multithreaded environment, and more particularly to systems and methods for performing concurrency restriction and throttling over contended locks.
Description of the Related Art
Concurrent applications running on modern multicore architectures are quite often over-threaded, that is, they use more threads than needed to achieve optimal performance. In a multiprocessor environment with threads and preemptive scheduling, threads can participate in a mutual exclusion protocol through the use of lock or “mutex” constructs. A mutual exclusion lock can either be in a locked state or an unlocked state, and only one thread can hold or own the lock at any given time. The thread that owns the lock may be permitted to enter a critical section of code protected by the lock or otherwise access a shared resource protected by the lock. If a second thread attempts to obtain ownership of a lock while the lock is held by a first thread, the second thread may not be permitted to proceed into the critical section of code (or access the shared resource) until the first thread releases the lock and the second thread successfully claims ownership of the lock.
In modern multicore environments, it can often be the case that there are a large number of active threads, all contending for access to a shared resource. As multicore applications mature, situations in which there are too many threads for the available hardware resources to accommodate are becoming more common. As threads are added, even if the thread count remains below the number of logical CPUs, the application can reach a point at which aggregate throughput drops.
Very commonly, the degraded performance is the result of contended locks used by these applications to synchronize access to their shared data. The excess threads may lead to a scalability collapse phenomenon, where the throughput of threads circulating through a contended lock fades (or even drops abruptly) with the increase in the number of threads. This may happen due to competition for shared resources, such as computing cores or last-level cache (LLC). For instance, the increase in the number of distinct threads circulating through the lock may lead to increased cache pressure, resulting in cache misses and memory thrashing.